package com.ruoyi.query.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.query.entity.TableQueryColumn;
import com.ruoyi.query.service.TableQueryColumnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 列表查询列 前端控制器
 * </p>
 *
 * @author XiaShiLong
 * @since 2021-03-25
 */
@RestController
@RequestMapping("/tableQueryColumn")
@Api("列表可查询列")
public class TableQueryColumnController extends BaseController {

    private final TableQueryColumnService service;

    @Autowired
    public TableQueryColumnController(TableQueryColumnService service) {
        this.service = service;
    }

    @PreAuthorize("@ss.hasPermi('tableQueryColumn:get:getAll')")
    @ApiOperation("获取所有")
    @GetMapping("/{menuId}/{classPath}")
    public AjaxResult getAll(@PathVariable Long menuId, @PathVariable String classPath) throws ClassNotFoundException {
        return AjaxResult.success(service.getAll(menuId, classPath));
    }

    @PreAuthorize("@ss.hasPermi('tableQueryColumn:post:add')")
    @ApiOperation("保存可查询列")
    @Log(title = "保存可查询列", businessType = BusinessType.INSERT)
    @PostMapping("/{menuId}/{classPath}")
    public AjaxResult add(@PathVariable Long menuId, @PathVariable String classPath, @RequestBody List<TableQueryColumn> tableQueryColumnList) throws ClassNotFoundException {
        return toAjax(service.saveAll(menuId, classPath, tableQueryColumnList));
    }
}
